<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:c="http://java.sun.com/jsp/jstl/core"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:p="http://primefaces.prime.com.tr/ui"
                template="./../template/WorkspaceTemplate.xhtml">

    <ui:define name="top">
        
    </ui:define>

    <ui:define name="left">
       
    </ui:define>

    <ui:define name="right">
       
    </ui:define>

    <ui:define name="content">
        <style>
            .ui-state-highlight.ui-selected {
                color: blueviolet;
            }
        </style>
        <p:messages showDetail="true" />
        <p:growl id="growl" sticky="true"/>
        <p:panel style="height: 250px"> 
            <h:form id="searchSOForm" >
                <p:ajaxStatus style="width: 16px;height: 16px;">
                    <f:facet name="start">
                        <h:graphicImage value="./../images/ajaxloading.gif"/>
                    </f:facet>
                    <f:facet name="complete">
                        <h:outputText value=""/>
                    </f:facet>
                </p:ajaxStatus>
                <p:messages />

                <h:panelGrid columns="3" cellpadding="10">
                    <h:outputLabel for="salesOrderIdStr" style="font-weight: bold" value="Enter Sales Order Id: "/>
                    <h:inputText required="true" label="Sales Order" requiredMessage="Sales order Id is required."
                                 id="salesOrderIdStr" value="#{soManagerBean.salesOrderIdStr}"/>
                    <p:commandButton update="searchSOForm" oncomplete="soDialog.show();" image="ui-icon ui-icon-search"/>    
                </h:panelGrid>
                <p:commandButton id="button" value="Next" ajax="false" action="#{soManagerBean.populateSalesOrder}"/>
            </h:form>
        </p:panel>

        <p:dialog header="searchSalesOrder" widgetVar="soDialog" hideEffect="explode" height="600" width="800">    
            <h:form id="soForm">
                <p:dataTable var="salesOrder" value="#{ssoManagerBean.sos}"
                             emptyMessage="No Sales Orders found with given criteria" selection="#{soManagerBean.salesOrder}" selectionMode="single" widgetVar="sotbl">

                    <f:facet name="header">
                        <p:outputPanel>
                            <h:outputText value="Search all fields:" />
                            <p:inputText id="globalFilter" onkeyup="sotbl.filter()" style="width:150px" />
                        </p:outputPanel>
                    </f:facet>

                    <p:column filterBy="#{salesOrder.salesOrderIdStr}" 
                              headerText="Sales Order Id" footerText="contains"
                              filterMatchMode="contains">
                        <h:outputText value="#{salesOrder.salesOrderIdStr}" />
                    </p:column>

                    <p:column filterBy="#{salesOrder.purchaseOrder.poNumber}" 
                              headerText="PO Number" footerText="contains"
                              filterMatchMode="contains">
                        <h:outputText value="#{salesOrder.purchaseOrder.poNumber}" />
                    </p:column>

                    <p:column filterBy="#{salesOrder.customer.clientId}"
                              headerText="Client Id" footerText="contains">
                        <h:outputText value="#{salesOrder.customer.clientId}" />
                    </p:column>

                    <p:column filterBy="#{salesOrder.customer.companyName}"
                              headerText="Client Name" footerText="contains">
                        <h:outputText value="#{salesOrder.customer.companyName}" />
                    </p:column>

                    <p:column filterBy="#{salesOrder.customer.category}" 
                              headerText="Customer Category" footerText="exact"
                              filterOptions="#{ssoManagerBean.categoryOptions}"
                              filterMatchMode="exact">
                        <h:outputText value="#{salesOrder.customer.category}" />
                    </p:column>

                    <p:column filterBy="#{salesOrder.dateStr}" 
                              headerText="Sales Order Date" footerText="contains"
                              filterMatchMode="contains">
                        <h:outputText value="#{salesOrder.salesOrderDate}">
                            <f:convertDateTime pattern="MMMM dd, yyyy"/>
                        </h:outputText>    
                    </p:column>

                    <p:column filterBy="#{salesOrder.salesOrderStatus}"
                              headerText="Sales Order Status" footerText="exact"
                              filterOptions="#{ssoManagerBean.statusOptions}"
                              filterMatchMode="exact">
                        <outputText value="#{salesOrder.salesOrderStatus}" />
                    </p:column>
                </p:dataTable>
                <p:commandButton value="Select Sales Order" update="searchSOForm" oncomplete="soDialog.hide()"/>
            </h:form>
        </p:dialog>
    </ui:define>

    <ui:define name="bottom">
       
    </ui:define>

</ui:composition>
